package com.zhuhanpeng.cloud.login.control;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import com.zhuhanpeng.cloud.api.entity.LoginEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/api")
@Slf4j
public class KaptchaController {
    /**
     * @Title: loginCheck
     * @param request
     * @param kaptchaReceived
     * @return String
     * @Description:  验证码登录
     * @
     *
     * @date: 2017年11月21日
     */
    @RequestMapping(value = "kaptcha", method = RequestMethod.POST)
    @ResponseBody
    public String loginCheck(HttpServletRequest request, @RequestBody LoginEntity loginEntity){

        log.info(loginEntity.toString());
        System.out.println("111");
        //用户输入的验证码的值
        String kaptchaExpected = (String) request.getSession().getAttribute(
                com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY);

        //校验验证码是否正确
        if (loginEntity.getCaptcha() == null || !loginEntity.getCaptcha().equals(kaptchaExpected)) {

            return "kaptcha_error";//返回验证码错误
        }
        //校验用户名密码
        // ……
        // ……
        return "success"; //校验通过返回成功
    }



}